package cn.gxa.edu_adm.servlet;

import cn.gxa.edu_adm.bean.Course;
import cn.gxa.edu_adm.commn.model.ResultData;
import cn.gxa.edu_adm.service.impl.CourseServiceImpl;
import cn.gxa.edu_adm.utils.StringUtils;
import com.alibaba.fastjson.JSON;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(urlPatterns = "/courseAdd")
public class CourseAddServlet  extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       //前端参数
        String  couName= StringUtils.formatString(req.getParameter("couName"));
        Integer  couTypeId= StringUtils.formatInteger(req.getParameter("couTypeId"));
        Double  couScore= StringUtils.formatDouble(req.getParameter("couScore"));
        String  couContext= StringUtils.formatString(req.getParameter("couContext"));
        //封装对象中
        Course  course=new Course();
        course.setCouName(couName);
        course.setCouContext(couContext);
        course.setCouScore(couScore);
        course.setCouTypeId(couTypeId);
        ResultData   resultData=new CourseServiceImpl().insert(course);
        System.out.println(JSON.toJSONString(resultData));
        //响应给前端
        PrintWriter writer = resp.getWriter();
        writer.print(JSON.toJSONString(resultData));
        writer.close();
    }
}
